package com.think.teaching.mapper;

import com.think.teaching.model.Course;
import com.think.teaching.model.CourseUser;

import java.util.Map;

import org.apache.ibatis.annotations.One;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.mapping.FetchType;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.lowagie.text.List;

/**
 * <p>
 * 用户课程 Mapper 接口
 * </p>
 *
 * @author think
 * @since 2020-08-12
 */
public interface CourseUserMapper extends BaseMapper<CourseUser> {
	
	@Select("SELECT * FROM course WHERE id IN (SELECT course_id FROM course_user Where student_id=#{userId}) AND delflag != 1")
	@Result(column="id",property="id")
	@Result(column="id",property="teacherInfo",one = @One(select = "com.think.teaching.mapper.CourseMemberMapper.GetFirstMember",fetchType = FetchType.EAGER))
	public IPage<Course> ListCourseUserWithTagAndType(IPage<Course> page,@Param("userId")Integer userId);
	
	
	@Select("<script>"
			+ "SELECT cu.created_time,si.true_name,course.course_name,course.`mode` FROM course_user cu LEFT JOIN student_info si ON cu.student_id=si.user_id LEFT JOIN course ON cu.course_id=course.id"
			+
			"<if test='course gt 0'>WHERE cu.course_id =#{course}</if>"
			+ "</script>")
	public IPage<Map<String,Object>> ListCourseUser(IPage<Map<String,Object>> page,@Param("course")Integer course);
}
